from robot.api import logger

def embed_button_and_script():
    html_with_js = """
    <button id="replaceButton" style="margin: 20px; padding: 10px 20px; font-size: 16px;">
        替换图片
    </button>

    <script>
        document.getElementById('replaceButton').addEventListener('click', async () => {
            try {
                const response = await fetch('http://127.0.0.1:5000/replace', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        source: 'current.png',
                        target: 'sample.png',
                    }),
                });
                const data = await response.json();
                alert(data.message);
            } catch (error) {
                console.error('请求失败:', error);
                alert('替换失败，请检查控制台日志。');
            }
        });
    </script>
    """
    logger.info(html_with_js, html=True)